#!/bin/bash

app_name="zookeeper "
app_home='/opt/app/zkapp/zookeeper'
filter_str=$app_home'/bin/zkServer.sh status&&echo `jps|egrep "QuorumPeerMain"`'
function print()
{
        echo " │"
        echo " ├$app_name $1 节点"
        echo " └───────────────"
}
function start()
{
	echo ""
	echo "#$app_name 集群启动中..."
	ssh bigdata1 $app_home'/bin/zkServer.sh start'
	print 1
	ssh bigdata2 $app_home'/bin/zkServer.sh start'
	print 2
	ssh bigdata3 $app_home'/bin/zkServer.sh start'
	print 3
	sleep 1
}
function stop()
{
	echo ""
	echo "#$app_name 集群关闭中..."
    ssh bigdata1 $app_home'/bin/zkServer.sh stop'
	print 1
	ssh bigdata2 $app_home'/bin/zkServer.sh stop'
	print 2
	ssh bigdata3 $app_home'/bin/zkServer.sh stop'
	print 3
	sleep 1
}
function status()
{
	echo ""
	echo "#$app_name 集群状态..."
	ssh bigdata1 $filter_str
	print 1
	
	ssh bigdata2 $filter_str
	print 2
	
	ssh bigdata3 $filter_str
	print 3
}
arg=$1
if [ "$arg" = "" ];then
	echo "请传入[start|stop|restart|status]参数,不传默认为[status]"
	arg="status"

fi
if [ "$arg" = "start" ];then
	start
	status
elif [ "$arg" = "stop" ];then
	stop
	status
elif [ "$arg" = "restart" ];then
	stop
	start
	status
elif [ "$arg" = "status" ];then
	status
else
	echo "请传入start|stop|restart|status参数"
fi
